#include "offsets.h"
#include "../include/handlers_asm.h"

.align HANDLER_ALIGNMENT
.globl handlers
handlers:
.set N, 0
.rept 256
pushq $N
jmp error_code_check
.align HANDLER_ALIGNMENT
.set N, N+1
.endr
.globl end_handlers
end_handlers:

error_code_check:

movq (%rsp), %r15
callq pre_check

addq $8, %rsp //pop interrupt number

cmpq $0x10, 16(%rsp)
jne no_error_code

movq (%rsp), %r15
callq save_error_code

addq $8, %rsp //pop error code

no_error_code:

// change RIP on the stack
movabsq $INTERRUPTS, %rax
movq interrupts_data__return_addr(%rax), %rax
movq %rax, (%rsp)

iretq
